package com.example.zhaoping.controller;


import com.example.zhaoping.domain.Companies;
import com.example.zhaoping.domain.ResponseResult;
import com.example.zhaoping.service.ICompaniesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author czx
 * @since 2024-12-24
 */
@RestController
@RequestMapping("/companies")
@Api(tags = "公司管理")
public class CompaniesController {
    @Autowired
    private ICompaniesService companiesService;
    @ApiOperation("分页查询公司列表")
    @GetMapping("/list")
    public ResponseResult companyList(Integer pageNum,Integer pageSize,String name){
        return companiesService.companiesList(pageNum,pageSize,name);
    }


    @ApiOperation("根据id查询公司")
    @GetMapping("/getcompany/{id}")
    public ResponseResult getCompany(@PathVariable Long id){
        Companies company = companiesService.getById(id);
        return ResponseResult.okResult(company);
    }

    @ApiOperation("新增公司")
    @PostMapping("/addcompany")
    public ResponseResult addCompany(@RequestBody Companies companies){
        companiesService.save(companies);
        return ResponseResult.okResult();
    }
    @ApiOperation("修改公司")
    @PutMapping("/updatecompany")
    public ResponseResult updateCompany(@RequestBody Companies companies){
        companiesService.updateById(companies);
        return ResponseResult.okResult();
    }

    @ApiOperation("删除公司")
    @DeleteMapping("/deletecompany/{id}")
    public ResponseResult deleteCompany(@PathVariable Long id){
        companiesService.removeById(id);
        return ResponseResult.okResult();
    }



}
